<?php

/**
 * This is the model class for table "SanPham".
 *
 * The followings are the available columns in table 'SanPham':
 * @property integer $IDSP
 * @property string $MASP
 * @property string $TENSP
 * @property integer $IDHSX
 * @property string $GIATIEN
 * @property integer $SOLUONG
 * @property string $HINHANH
 */
class SanPham extends CActiveRecord implements IECartPosition
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return SanPham the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}


    public function getId()
    {
        //return 'SanPham'.$this->IDSP;
        return $this->IDSP;

    }

    /**
     * @return float price
     */
    public function getPrice()
    {
        return $this->GIATIEN;
        //return 'SanPham'.$this->GIATIEN;
    }


	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'SanPham';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('MASP, TENSP, IDHSX', 'required'),
			array('IDHSX, SOLUONG', 'numerical', 'integerOnly'=>true),
			array('MASP', 'length', 'max'=>6),
			array('TENSP', 'length', 'max'=>25),
			array('GIATIEN', 'length', 'max'=>10),
			array('HINHANH', 'length', 'max'=>100),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('IDSP, MASP, TENSP, IDHSX, GIATIEN, SOLUONG, HINHANH', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'IDSP' => 'Idsp',
			'MASP' => 'Masp',
			'TENSP' => 'Tensp',
			'IDHSX' => 'Idhsx',
			'GIATIEN' => 'Giatien',
			'SOLUONG' => 'Soluong',
			'HINHANH' => 'Hinhanh',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('IDSP',$this->IDSP);
		$criteria->compare('MASP',$this->MASP,true);
		$criteria->compare('TENSP',$this->TENSP,true);
		$criteria->compare('IDHSX',$this->IDHSX);
		$criteria->compare('GIATIEN',$this->GIATIEN,true);
		$criteria->compare('SOLUONG',$this->SOLUONG);
		$criteria->compare('HINHANH',$this->HINHANH,true);

		return new CActiveDataProvider($this, array(
			'criteria' => $criteria,
                        'sort' => array(
                                'defaultOrder' => 'MASP ASC', // Mặc định sắp xếp theo trường MASP tăng dần
                        ),
                        'pagination' => array(
                                'pageSize' => 6 // Thiết lập mỗi trang 6 bản ghi
                        ),
                ));
	}


}